class MusicPlayer {
  var playlist: List[String] = Nil    
  var currentSong: String = ""         
  var playMode: String = "loop"        

  def addSong(song: String): Unit = {
    playlist = playlist :+ song      
  }

  def removeSong(song: String): Unit = {
    playlist = playlist.filter(_ != song)  
  }

  def play(): Unit = {
    currentSong = playlist.headOption.getOrElse("") 
  }

  def next(): Unit = {
    
    playMode match {
      case "loop" => loopPlayNext()
      case "shuffle" => shufflePlayNext()
      case "single" => singlePlayNext()
      case _ => println("Unknown play mode!")
    }
  }

  def loopPlayNext(): Unit = {
    val index = playlist.indexOf(currentSong) 
    if (index == playlist.length - 1) {       
      currentSong = playlist.headOption.getOrElse("")
    } else {                                   
      currentSong = playlist(index + 1)
    }
  }

  def shufflePlayNext(): Unit = {
   
    currentSong = scala.util.Random.shuffle(playlist).headOption.getOrElse("")
  }

  def singlePlayNext(): Unit = {
    
   
    if (playlist.contains(currentSong)) {
      currentSong = currentSong
    } else {
      currentSong = playlist.headOption.getOrElse("")
    }
  }
}
